import numpy as np
import matplotlib.pyplot as plt
from scipy.special import gamma
import cv2
import cv2 as cv



if __name__ == '__main__':
    image = cv.imread('/Users/yida/Desktop/subimg/2_2_5.jpg')#载入图像

    HSV_img = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)#图像转化为HSV图像
    H, S, V = cv2.split(HSV_img)#HSV图像分裂3层

    V_channel = np.mean(V)#求V图均值
    print(V_channel)#输出均值
    cv.imshow('souce image', V)
    #非对称广义高斯开始
    aref = 1.46038
    var_l = 69.3625
    var_r = 22.0368
    miu = 181.239
    x_l = np.linspace(0, miu, 1000)
    x_r = np.linspace(miu, 255, 1000)
    beta_l = var_l * (np.sqrt(gamma(1 / aref) / gamma(3 / aref)))
    beta_r = var_r * (np.sqrt(gamma(1 / aref) / gamma(3 / aref)))

    y_l = (aref / ((beta_l + beta_r) * gamma(1 / aref))) * np.exp(-((-x_l + miu) / beta_l) ** aref)
    y_r = (aref / ((beta_l + beta_r) * gamma(1 / aref))) * np.exp(-((x_r - miu) / beta_r) ** aref)

    print(x_l)
    np.sum(y_l)

    plt.plot(x_l, y_l)
    plt.plot(x_r, y_r)
    # 非对称广义高斯结束

    plt.hist(V.ravel(), 256, [0, 255], density=1, cumulative=False, histtype='barstacked')
    plt.show()
    cv.waitKey(0)
    cv.destroyAllWindows()



